#ifndef DATAS_H
#define DATAS_H

#include <QLocale>
#include "config/ConfigDataModel.h"
#include "config/Items.h"

#define CONFIG_ITEM(TYPE,ID) \
    public: TYPE* ID = nullptr; \
    public: Q_PROPERTY(TYPE* ID MEMBER ID)

#define CONFIG_ENUM(TYPE,ID) \
    CONFIG_ITEM(ItemEnum,ID)

#define CONFIG_FLAG(TYPE,ID) \
    CONFIG_ITEM(ItemFlag,ID)

#define CONFIG_DATA_MODEL(TYPE,ID) \
    public: TYPE* ID = nullptr; \
    public: Q_PROPERTY(TYPE* ID MEMBER ID)

class UI;
class Translate;
class ConfigData : public ConfigDataModel
{
    Q_OBJECT
public:
    explicit ConfigData(QObject *parent = nullptr);
    static ConfigData& instance()
    {
        static ConfigData cd;
        return cd;
    }

    enum PickMode { All, Custom, None};
    Q_ENUM(PickMode)

    CONFIG_ENUM(QLocale::Language, myLanguage)
    CONFIG_ENUM(PickMode, pickMode)
    CONFIG_ITEM(ItemStringList, disabledApps)
    CONFIG_ITEM(ItemString, updateURL)
    CONFIG_ITEM(ItemBool, autoStart)
    CONFIG_ITEM(ItemBool, checkUpdate)

    CONFIG_DATA_MODEL(UI, ui)
    CONFIG_DATA_MODEL(Translate, translate)

protected:
    virtual void resetSelf() override;
};

class UI : public ConfigDataModel
{
    Q_OBJECT
public:
    explicit UI(QObject *parent = nullptr);

    enum Theme { Light, Dark};
    Q_ENUM(Theme)

    enum Direction { Up, Down};
    Q_ENUM(Direction)

    CONFIG_ITEM(ItemInt, floatButtonSize)
    CONFIG_ITEM(ItemInt, noteWindowWidth)
    CONFIG_ITEM(ItemInt, noteWindowEdge)
    CONFIG_ENUM(Direction, noteWindowDirection)
    CONFIG_ITEM(ItemInt, triangleWidth)
    CONFIG_ITEM(ItemInt, triangleHeight)
    CONFIG_ITEM(ItemBool, isPinning)

    CONFIG_ENUM(Theme, uiTheme)

protected:
    virtual void resetSelf() override;
};

class Translate : public ConfigDataModel
{
    Q_OBJECT
public:
    explicit Translate(QObject *parent = nullptr);

    enum API { Baidu, Google, YouDao, Kingsoft, HanDict};
    Q_ENUM(API)

    enum OCR_LANG {
        CHN_ENG,
        ENG,
        JAP,
        KOR,
        FRE,
        SPA,
        POR,
        GER,
        ITA,
        RUS
    };
    Q_ENUM(OCR_LANG)
    /*
    - CHN_ENG：中英文混合
    - ENG：英文
    - JAP：日语
    - KOR：韩语
    - FRE：法语
    - SPA：西班牙语
    - POR：葡萄牙语
    - GER：德语
    - ITA：意大利语
    - RUS：俄语
    */


    CONFIG_FLAG(API, enabledAPIs)
    CONFIG_ITEM(ItemOption, primaryAPI)
    CONFIG_ENUM(OCR_LANG, OCRLang)
    CONFIG_ITEM(ItemBool, ignoreCRLF) // 换行
    CONFIG_ITEM(ItemInt, networkTimeout) // 毫秒，网络请求超时时间
    CONFIG_ITEM(ItemString, baiduTokenURL)
    CONFIG_ITEM(ItemShortcut, OCRTextShortcut)
    CONFIG_ITEM(ItemShortcut, OCRTranslateShortcut)
    CONFIG_ITEM(ItemShortcut, searchBarShortcut)

protected:
    virtual void resetSelf() override;
};

#undef CONFIG_ITEM
#undef CONFIG_ENUM
#undef CONFIG_FLAG
#undef CONFIG_DATA_MODEL

#endif // DATAS_H
